<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/system/common/libs/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="/system/common/libs/bootstrap/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/system/common/custom/css/common.css">
    <link rel="stylesheet" type="text/css" href="/frame/css/primary.css" class="css-href"/>
    <script language="JavaScript" src="/system/common/libs/js/jquery.min.js"></script>
    <script language="JavaScript" src="/system/common/libs/bootstrap/js/bootstrap.min.js"></script>
    <script language="JavaScript" src="/system/common/libs/laydate/laydate.js"></script>
    <script language="JavaScript" src="/system/common/custom/js/common.js"></script>
    <script language="JavaScript" src="/system/common/libs/layer/layer.js"></script>
    <script language="JavaScript" src="/system/common/libs/layer/layui.js"></script>
    <style>
        .error-info {
            display: none;
            color: #a94442;
        }
        table{
            margin: 0 auto;
        }
        table tr td{
            height: 32px;
            width: 360px;
        }
        #setPwd table tr td input{
            height: 32px!important;
            width: 360px;
            margin-bottom: 20px!important;
        }
        .btn-submit{
            height: 32px!important;
            width: 80px!important;
            line-height: 32px;
            margin-left: 0!important;
        }
        .myContainer{
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div class="container myContainer">
    <form id="setPwd" style="margin-top: 15px">
        <table id="xx">
           <tr>
               <td> <h3 style="color: #808080!important;margin: 20px 0;">请输入新密码</h3></td>
           </tr>
            <tr>
                <td><input type="password" class="form-control" name="pwd" required="required" placeholder="请输入新密码"></td>
            </tr>
            <tr>
                <td><input type="password" class="form-control" name="repwd" required="required" placeholder="请再次输入新密码"></td>
            </tr>
            <tr>
                <td><input type="button" class="btn-submit btn-primary" value="提交"></td>
            </tr>
        </table>
        <table id="yy" style="display: none">
            <tr>
                <td> <h3 style="color: #808080!important;margin: 20px 0;">密码修改成功</h3></td>
            </tr>
            <tr>
                <td><a href="/" target="_top">返回首页</a></td>
            </tr>
        </table>
    </form>
</div>
</body>
<script>
    $(function() {
        $('form[id="setPwd"] input').on('keyup', function() {
            if(!$(this).val()) {
                $(this).addClass('xinput-error');
                $.x_alertMsg('请输入密码！', 0, 5000);
            }else if($(this).attr('name') == 'repwd') {
                if($(this).val() != $('input[name=pwd]').val()) {
                    $(this).addClass('xinput-error');
                    $.x_alertMsg('两次输入的密码不一样！', 0, 5000);
                } else {
                    $('form[id="setPwd"] input').removeClass('xinput-error');
                }
            }else if($(this).attr('name') == 'pwd'){
                if($(this).val() != $('input[name=repwd]').val()) {
                    $(this).addClass('xinput-error');
                    $.x_alertMsg('两次输入的密码不一样！', 0, 5000);
                } else {
                    $('form[id="setPwd"] input').removeClass('xinput-error');
                }
            }
        });

        $('form[id="setPwd"] .btn-submit').on('click', function() {
            if ($('.xinput-error').length > 0) {
                $.x_alertMsg("请完善数据!",0);
            } else {
                var pwd = $("input[name=pwd]").val();
                var repwd = $("input[name=repwd]").val();
                var token = location.search.substring(7);
                if (pwd && repwd) {
                    jQuery.ajax({
                        url: "/public/ChangePasswordFromEmailLink.do",
                        type: "post",
                        data: {password: pwd,token:token},
                        success: function (data) {
                            if (data && data.status == "1") {
                                $.x_alertMsg("修改密码成功!",1);
                                $("#xx").remove();
                                $("#yy").show();
                            } else {
                                $.x_alertMsg(data['message'],0);
                            }
                        }
                    });
                } else {
                    $.x_alertMsg("两次输入的密码不一致，请重新输入!",0);
                }
            }
        });
    });
</script>
</html>